package cn.easybuy.service.impl;

import cn.easybuy.dao.UserDao;
import cn.easybuy.dao.impl.UserDaoImpl;
import cn.easybuy.entity.User;
import cn.easybuy.service.UserService;
import cn.easybuy.util.SecurityUtils;

public class UserServiceImpl implements UserService {

	private UserDao dao = new UserDaoImpl();
	@Override
	public boolean register(User user) {
		
		//密码加密
		String securityPwd = SecurityUtils.md5Hex(user.getPassword());
		user.setPassword(securityPwd);
		
		return dao.add(user)>0;
	}
	@Override
	public User login(String loginName, String password) {
		//先根据登录名 查出对应的 记录
		User user = dao.findUserByLoginName(loginName);
		
		if (user != null) {
			//然后 比较 密码
			if (user.getPassword().equals(SecurityUtils.md5Hex(password))) {
				return user;
			}
		}
		
		return null;
	}

}
